import {
  createVuePlugin
} from 'vite-plugin-vue2'
import path from "path"
import autoprefixer from 'autoprefixer';
import postCssPxToRem from 'postcss-pxtorem';
import legacy from '@vitejs/plugin-legacy'

const defaultSettings = require('./src/settings.js')

const name = defaultSettings.title || 'vue Admin Template' // page title

export default {
  resolve: {
    extensions: ['.js', '.vue', '.json'],
    alias: {
      "@": path.resolve(__dirname, "src"), // 结尾如果缺失‘,’会导致图片出不来
    },
  },
  css: {

    postcss: {
      plugins: [
        autoprefixer({
          overrideBrowserslist: ['Android 4.1', 'iOS 7.1', 'Chrome > 31', 'ff > 31', 'ie >= 8'],
        }),
        postCssPxToRem({
          // 自适应，px>rem转换
          rootValue: 100, // 75表示750设计稿，37.5表示375设计稿
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
          selectorBlackList: ['norem'], // 过滤掉norem-开头的class，不进行rem转换
        }),
        // 移除打包element时的@charset警告
        // 忽略element的scss字符集，报错: @charset" must be the first rule in the file
        {
          postcssPlugin: 'internal:charset-removal',
          AtRule: {
            charset: (atRule) => {
              if (atRule.name === 'charset') {
                atRule.remove()
              }
            }
          }
        }
      ],
    },
  },
  assetsDir: './',
  open: false,
  https: false,
  server: {
    port: 9003, // 本地服务端口
    // proxy: {
    //   '/api': {
    //     target: 'http://192.168.101.17:5210',
    //     changeOrigin: true,
    //     pathRewrite: {
    //       '^/api': ''
    //     }
    //   },
    //   '/es': {
    //     target: 'http://192.168.101.233:6006',
    //     changeOrigin: true,
    //     ws: true,
    //     pathRewrite: {
    //       '^/es': ''
    //     }
    //   }
    // }
  },
  build: {
    target: ['es2015'],
    chunkSizeWarningLimit: 2000
  },
  plugins: [createVuePlugin(), legacy({
    target: ['ie 11']
  })],
}